#include <iostream>
#include "CServer.h"
#include "configMgr.h"
#include "const.h"
#include "RedisMgr.h"


void TestRedisMgr() {
	assert(RedisMgr::GetInstance().Set("blogwebsite", "llfc.clu1"));
	std::string value = "";
	assert(RedisMgr::GetInstance().Get("blogwebsite", value));
	assert(RedisMgr::GetInstance().Get("nonekey", value) == false);
	assert(RedisMgr::GetInstance().HSet("bloginfo", "blogwebsite", "llfc.club"));
	assert(RedisMgr::GetInstance().HGet("bloginfo", "blogwebsite") != "");
	assert(RedisMgr::GetInstance().ExistsKey("bloginfo"));
	assert(RedisMgr::GetInstance().Del("bloginfo"));
	assert(RedisMgr::GetInstance().Del("bloginfo"));
	assert(RedisMgr::GetInstance().ExistsKey("bloginfo") == false);
	assert(RedisMgr::GetInstance().LPush("lpushkey1", "lpushvalue1"));
	assert(RedisMgr::GetInstance().LPush("lpushkey1", "lpushvalue2"));
	assert(RedisMgr::GetInstance().LPush("lpushkey1", "lpushvalue3"));
	assert(RedisMgr::GetInstance().RPop("lpushkey1", value));
	assert(RedisMgr::GetInstance().RPop("lpushkey1", value));
	assert(RedisMgr::GetInstance().LPop("lpushkey1", value));
	assert(RedisMgr::GetInstance().LPop("lpushkey2", value) == false);
	RedisMgr::GetInstance().Close();
}
int main() {
	std::string gate_port_str = configMgr::GetInst()["GateServer"]["port"];
	unsigned short gate_port = atoi(gate_port_str.c_str());
	try {
		net::io_context ioc{1};
		unsigned short port = static_cast<unsigned short>(8080);
		boost::asio::signal_set signals(ioc, SIGTERM, SIGINT);
		signals.async_wait([&ioc](const boost::system::error_code& ec, int signal_number) {
			if (!ec) {
				return;
			}
			ioc.stop();
			});

		std::make_shared<CServer>(ioc, port)->Start();
		ioc.run();
	}
	catch(std::exception& e){
		std::cerr << "initialize Err " << e.what() << std::endl;
		return EXIT_FAILURE;
	}
}